package org.kl.bf.sso;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

/**
 * 工程量月报统计汇总
 * @author QJ
 * @date 2014年12月30日
 */
@Component
public class SsoDao {
	@Autowired
	private JdbcTemplate jdbcTemp;
	
	public Integer checkOaSid(String sid){
		String sql ="select count(*) from v_sso_oa t where t.sid = "+sid;
		return jdbcTemp.queryForObject(sql, Integer.class);
	}
	
	public Integer checkSsoToken(String loginNo,String token){
		String sql ="select count(*) from sso_log t where t.finish_flag = 0 and target_system='school' and t.login_no = '"+loginNo+"' and t.sso_token='"+token+"'";
		return jdbcTemp.queryForObject(sql, Integer.class);
	}
	
	public int finishSsoToken(String loginNo,String token){
		String sql ="update sso_log t set t.finish_flag = 1,t.finish_date = sysdate where t.login_no = '"+loginNo+"' and t.sso_token='"+token+"'";
		return jdbcTemp.update(sql);
	}
	
	public int insertSsoToken(String token,String loginNo,String targetSystem){
		String sql ="insert into sso_log(sso_token,sso_date,finish_flag,login_no,source_system,target_system) values('"+token+"',sysdate,0,'"+loginNo+"','school','"+targetSystem+"')";
		return jdbcTemp.update(sql);
	}
}
